import { Controller, Get, Post, Body, Patch, Param, Delete, ParseIntPipe } from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from '../auth/dto/register.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { UserPipeValidate } from './pipe/user.pipe';
import { VisitRoleCheck } from '@/auth/decorators/visitCheck';


@Controller('user')
@ApiTags('user用户模块')
export class UserController {
  constructor(private readonly userService: UserService) { }

  @ApiOperation({ summary: '添加用户', description: '添加用户传递唯一id' })
  @ApiBody({ type: CreateUserDto, description: "传入的请求体,所有参数必须完整" })
  @Post()
  @ApiResponse({ status: 200, description: '操作成功状态码', type: null })
  @VisitRoleCheck([])
  // 添加验证规则
  async create(@Body(UserPipeValidate) createUserDto: CreateUserDto) {
    console.log('xxxxxx')
    return this.userService.create(createUserDto);
  }

  @Get()
  findAll() {
    return this.userService.findAll();
  }

  @Get('profile')
  @VisitRoleCheck(['normal'])
  authTest() {
    return {
      data: "visitRole传入的角色id,在role_guard进行token认证时,用户的角色id在数组里面,该路由就可以放行",
      status: 200,
      msg: "请求成功!"
    }
  }

  @ApiResponse({ status: 200, description: '查询成功', type: null })
  @Get(':id')
  findById(@Param('id', ParseIntPipe) id: number) {
    return this.userService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body(UserPipeValidate) updateUserDto: UpdateUserDto) {
    return this.userService.update(+id, updateUserDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userService.remove(+id);
  }


}
